import { defineStore } from 'pinia'
import { ref } from 'vue'

// 用户模块
export const useUserStore = defineStore(
  'mxh-cloud-notes-user',
  () => {
    const token = ref('')
    // 修改token
    const setToken = (newTokent) => {
      token.value = newTokent
    }
    // 删除token
    const removeToken = () => {
      token.value = ''
    }

    const user = ref({})
    // 修改user
    const setUser = (newUser) => {
      user.value = newUser
    }
    // 删除user
    const removeUser = () => {
      user.value = {}
    }

    return {
      token,
      setToken,
      removeToken,
      user,
      setUser,
      removeUser
    }
  },
  {
    persist: true
  }
)
